#include <iostream>

#include "protonos8.hpp"

int
main(int argc, char* argv[])
{
	try
	{
#if 0
		std::cout << "sizeof(pb_address) = " << sizeof(protonos8::pb_address) << std::endl;
		std::cout << "sizeof(req_hdr) = " << sizeof(protonos8::req_hdr) << std::endl;
		std::cout << "sizeof(ack_hdr) = " << sizeof(protonos8::ack_hdr) << std::endl;
		std::cout << "sizeof(pb_info_ack) = " << sizeof(protonos8::pb_info_ack) << std::endl;

		return 1;
#endif
		if (argc != 4) {
			std::cerr << "Usage: protonos8-test <host> <port> <slot>\n";
			return 1;
		}

		protonos8::client client(argv[1], argv[2]);

		uint32_t data;

		std::cout << "client.info: ack_result=" << (int)client.info(data) << "; ";
		std::cout << "protonos8 version info=0x" << std::hex << (int)data << std::dec << ".\n";

		std::size_t slot = atoi(argv[3]);

		uint16_t adc[32];

		std::cout <<
			"client.init_m22[" << slot <<
			"]: ack_result=" << (int)client.init_m22(slot, 0) <<
			"\n";


		for (;;) {
			std::cout <<
				"client.read_m22[" << slot <<
				"]: ack_result=" << (int)client.read_m22(slot,0xffff, adc);

			std::cout << "; data=[" << std::hex << adc[0] <<
				"," << adc[1] <<
				"," << adc[2] <<
				"," << adc[3] <<
				"," << adc[4] <<
				"," << adc[5] <<
				"," << adc[6] <<
				"," << adc[7] <<
				"," << adc[8] <<
				"," << adc[9] <<
				"," << adc[10] <<
				"," << adc[11] <<
				"," << adc[12] <<
				"," << adc[13] <<
				"," << adc[14] <<
				"," << adc[15] <<
				std::dec <<
				"]\r";
		}

	} catch (std::exception& e) {
		std::cerr << "Exception: " << e.what() << "\n";
	}

	return 0;
}
